"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.arrayMoveImmutable = arrayMoveImmutable;
exports.arrayMoveMutable = arrayMoveMutable;

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

function arrayMoveMutable(array, fromIndex, toIndex) {
  var startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;

  if (startIndex >= 0 && startIndex < array.length) {
    var endIndex = toIndex < 0 ? array.length + toIndex : toIndex;

    var _array$splice = array.splice(fromIndex, 1),
        _array$splice2 = (0, _slicedToArray2.default)(_array$splice, 1),
        item = _array$splice2[0];

    array.splice(endIndex, 0, item);
  }
}

function arrayMoveImmutable(array, fromIndex, toIndex) {
  var newArray = (0, _toConsumableArray2.default)(array);
  arrayMoveMutable(newArray, fromIndex, toIndex);
  return newArray;
}